home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / pdselect / awnp / awnp-docs / gsexample.doc < prev    next >
Text File  |  2000-02-16  |  8KB  |  239 lines

  1.  Working through these tutorials in order is the best way to learn to build
  2. GUI's with AWNPipe. A few minutes here will save you hours of development
  3. time later.
  4.  
  5.  TUTORIAL 1
  6. -----------
  7.  
  8. Building GUIs ca be VERY easy, This first tutorial will develope a simple GUI.
  9.  
  10.  Create a simple 4 line text file called first.gui . (you can dragselect and the Right Amiga C to copy text from thedse docs)
  11.  
  12. title "My first GUI" defaultgadgets
  13. button gadgettext "YES"
  14. button gt "NO"
  15. open
  16.  
  17. Now in a shell 'copy first.gui awnpipe:/xc'.
  18.  
  19. That was easy. You already guessed that gt was a short form for gadgettext.
  20.  
  21. Now we want to see what events the GUI sends. We can direct the events to a con by adding 'wcon:' to the end of the pipe name. Try
  22.  
  23. 'copy first.gui awnpipe:/xcwcon:'
  24.  
  25. Notice that the pipe replies to each line of the definition file as well as sending events.
  26.  
  27.  Now add a little text to the gui. We will also provide keyboard shortcuts for the gadgets.
  28.  
  29. title "My first GUI" defaultgadgets
  30. label  gt " Select YES or NO "
  31. button gadgettext "_YES"
  32. button gadgettext "_NO"
  33. open
  34.  
  35.  Thats worked, but it looks a little UGLY. Lets try a vertical layout instead of horizontal (the default).
  36.  
  37. title "My first GUI" defaultgadgets  vertical
  38. label  gt " Select YES or NO "
  39. button gadgettext "_YES"
  40. button gadgettext "_NO"
  41. open
  42.  
  43.  Getting better but we realy want the two gadgets side by side. To do that we will use a layout group. (le is layout end).
  44.  
  45. title "My first GUI" defaultgadgets  vertical
  46. label  gt " Select YES or NO "
  47. layout
  48. button gadgettext "_YES"
  49. button gadgettext "_NO"
  50. le
  51. open
  52.  
  53.  Thats much better! Looks good but it would be nicer if the window closed after the user selected yes or no. ( you also notice that the layout recieved a GID number so yes and no are now gadget 2 and 3)
  54.  
  55. title "My first GUI" defaultgadgets  vertical
  56. label  gt " Select YES or NO "
  57. layout
  58. button gadgettext "_YES" close
  59. button gadgettext "_NO" c
  60. le
  61. open
  62.  
  63.  Its done, it might even be usefull.
  64.  
  65.  Since we have a working gui lets use it to see a few other types of events the GUI can generate.
  66.  
  67. title "My first GUI" defaultgadgets  vertical  sendkeys sendqual help state
  68. label  gt " Select YES or NO "
  69. layout
  70. button gadgettext "_YES" close
  71. button gadgettext "_NO" c
  72. le
  73. open
  74.  
  75.  Activate and inactivate the window. Hold the mouse over each gadget. Type a few keys. Try the shift, alt ect.
  76.  
  77.  
  78. TUTORIAL 2
  79. -----------
  80.  
  81.  Now that we know how to designed a gui we want to be able to operate one.
  82. To follow this example you need a basic knowledge of ARexx. Have a look at
  83. the file Tutorial2.rx in the demos drawer.
  84.  
  85.  The program flow is straight forward. 3 simple steps.
  86.  
  87. 1. Default values are set. These are the values of the gadgets when
  88. the GUI opens.
  89.  
  90. 2. A routine (buildgui) is called to write the GUI definition to the pipe.
  91. (More on this routine later)
  92.  
  93. 3. Events are read from the pipe and processed untill the stream of events
  94. ends.
  95.  
  96. BUILDGUI
  97.  
  98.  The 'buildgui' routine contains the information defining the GUI window and
  99. its gadgets. The data is sent line by line to the 'topipe' routine which sends
  100. the data to the pipe, checks for errors, and returns the GID returned by the
  101. pipe. (more on 'topipe' later.)
  102.  
  103.  For most lines sent with 'topipe' the responce is ignored. For gadget
  104. definitions however the return value is stored so we can identify gadget
  105. events later on.
  106.  
  107. TOPIPE
  108.  
  109.  This routine takes a line of text and writes it to the pipe. The pipes
  110. responce is read. If everything is ok the second parameter of the responce is
  111. returned. This is the GID if a gadget is defined and a null string in most
  112. other cases. If an error ocurs the problem line is output and the script
  113. exits.
  114.  
  115.  You should use this routine or one like it when writing your own script for
  116. AWNPipe. It will help avoid common errors and make debugging much easier.
  117.  
  118. EVENT HANDLING
  119.  
  120.  The main loop reads an event from the pipe and parses it into its parts.
  121. The first word of an event always tells the event type. This information is
  122. used to call a routine for that type of event.
  123.  
  124. CLOSE EVENT
  125.  
  126. If a close event is received write a little text and then exit the script.
  127.  
  128. GADGET EVENT
  129.  
  130.  We check the second word of the event to see which gadget sent the event. For
  131. most gadgets we store event information and return. If the cancel gadget is
  132. the cause of the event we output some text and exit. If it was the done gadget
  133. we output the information for each gadget and exit. If it was the reset gadget
  134. we close the pipe, then create the gui again to restore the default values.
  135.  
  136. MENU EVENT
  137.  
  138.  The second word of a menu event is the menu number, the third word id the
  139. item number, and the forth the subitem number. This information is used to
  140. determine what action should be taken in responce to an event.
  141.  
  142.  Almost any GUI can be operated using this aproach demonstated in this
  143. tuorial.
  144.  
  145. TUTORIAL 3
  146. ---------------
  147.  
  148.  This tutorial deals with modifying a GUI after it has been opened. You
  149. should make sure you understand tutorial 2 before reading further.
  150.  
  151.  Three new gadgets have added to the gui. The load and save gadgets on the
  152. lower left, and a get file gadget that you do not see. The getfile gadget is
  153. unattached (ua) so it does not have aplace in the gui. More on the getfile
  154. gadget later.
  155.  
  156.  The window definiton line (in buildGUI:) has the modify option added to it.
  157. This means the pipe will look for modify commands after you fist open the
  158. window, and after each event is sent. Any number of modify commands can be
  159. written to the pipe, including 0 (none). After writing the modify comands
  160. 'continue' must be sent to the pipe to tell it to start sending events.
  161.  
  162.  Only two changes are made in the program flow.
  163.  
  164. 1.  After BUILDGUI is called to build and open the window we send a modify
  165. command to the pipe.
  166.  
  167. topipe('id 'savegad' dis 1 ref')
  168.  
  169.  The id specifies the save gadget, 'dis 1' disables it, and 'ref' refreshes
  170. it so the changes will show. (we want the save gadget disabled because the
  171. name gadget is empty at start up, and we need a name before we can save).
  172.  
  173. 2. In the mail loop a 'continue' is written to the pipe BEFORE we wait for an
  174. event. This tells to pipe to stop looking for modify commands and send an
  175. event.
  176.  
  177.  After an event is read from the pipe it automaticaly starts looking for more
  178. modify events. This means that modify commands can be used imediatly after
  179. receiving an event from the pipe.
  180.  
  181.  RESETFORM
  182.  
  183.  In tutorial 2 we had to close then open the GUI to reset its contents. With
  184. modify commands we can do this with the gui remaining open. The function
  185. restform is near the end of tutorial3.rx.
  186.  
  187.  This function sends a modify command for each of the gadgets resetting them
  188. to the default values. It also disables the save gadget.
  189.  
  190.  SAVEFORM
  191.  
  192.  This function is called when the user hits the save gadget. It writes the
  193. forms contents to a file in 't:'. The files name is the text from the name
  194. gadget with '.formdemo' appended to it. The save gadget is disabled unless
  195. the name gadget contains text. See the handling of namegad in the GADGET:
  196. routine.
  197.  
  198.  LOADFORM
  199.  
  200.  This function makes use of the unattached GETFILE gadget. A modify command
  201. is used to set the file name in the file requester, and to open the requester
  202. itself. The pattern used in the file requester was set when the gadget was
  203. created in the BUILDGUI routine.
  204.  
  205. call writeln(ca,'id 'getfilegad' fn "t:" s 1')
  206.  
  207. 'fn "t:"' sets the file requester to the drawer T:. 's 1' opens the
  208. requester.
  209.  
  210.  The return from the pipe to this modify command is read and parsed to get
  211. the file selected and to test if the user selected a file or aborted the
  212. requester. The reply from the pipe is ...
  213.  
  214. SUCCESS ["filename"]
  215.  
  216.  Success is 0 if the user aborts the file requester, non zero if a file is
  217. selected. The file name is allways returned in quotes since multiple files
  218. can be slected in some situations. (but not this situation).
  219.  
  220.  If the user selected a file, it is opened and the contents placed in the
  221. GUI. No error checking is done on the file in order to keep the tutorial
  222. clear and easy to understand.
  223.  
  224. TUTORIAL 4
  225. ---------------
  226.  
  227. Now for some simpler (but powerfull ideas).
  228.  
  229. Some interesting things can be done by setting a few simple aliases.
  230.  
  231. alias see  echo >awnpipe:/xc "defg*nbitmap fn []*nimage*nopen"
  232.  
  233. Now 'see FILENAME' will display pictures using your datatypes.
  234.  
  235. alias toolt  type awnpipe:/xi[]
  236.  
  237. Now 'toolt FILENAME' will display the tooltypes of FILENAME. (do not include .info in FILENAME).
  238.  
  239.